-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[llvm][Support] Fix missing-field-initializer warnings for crashreporter_annotations_t #154716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…notations_t Use `CRASHREPORTER_ANNOTATIONS_INITIALIZER` when possible, which will handle the field initialization for us. That's what we already do in compiler-rt: https://github.com/llvm/llvm-project/blob/0c480dd4b61e285bfda4de99c77da28922e64b94/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp#L799-L817 This way we won't get these warnings when the layout of crashreporter_annotations_t changes: ``` llvm/lib/Support/PrettyStackTrace.cpp:92:65: warning: missing field 'blah' initializer [-Wmissing-field-initializers] = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0 }; ^ 1 warning generated ```
|
@llvm/pr-subscribers-llvm-support Author: Michael Buch (Michael137) ChangesUse llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp Lines 799 to 817 in 0c480dd
This way we won't get these warnings when the layout of crashreporter_annotations_t changes: Full diff: https://github.com/llvm/llvm-project/pull/154716.diff 1 Files Affected:
diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp
index 3f03368c5d22e..8182468d28303 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -114,15 +114,27 @@ static void PrintCurStackTrace(raw_ostream &OS) {
// If any clients of llvm try to link to libCrashReporterClient.a themselves,
// only one crash info struct will be used.
extern "C" {
+#ifdef CRASHREPORTER_ANNOTATIONS_INITIALIZER
+// Available in CRASHREPORTER_ANNOTATIONS_VERSION 5+
+CRASHREPORTER_ANNOTATIONS_INITIALIZER()
+#else
+// Older CrashReporter annotations layouts
CRASH_REPORTER_CLIENT_HIDDEN
struct crashreporter_annotations_t gCRAnnotations
- __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION)))
-#if CRASHREPORTER_ANNOTATIONS_VERSION < 5
- = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
-#else
- = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0 };
-#endif
-}
+ __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) = {
+ CRASHREPORTER_ANNOTATIONS_VERSION,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+#if CRASHREPORTER_ANNOTATIONS_VERSION > 4
+ 0
+#endif // CRASHREPORTER_ANNOTATIONS_VERSION > 4
+};
+#endif // CRASHREPORTER_ANNOTATIONS_INITIALIZER
+} // extern "C"
#elif defined(__APPLE__) && HAVE_CRASHREPORTER_INFO
extern "C" const char *__crashreporter_info__
__attribute__((visibility("hidden"))) = 0;
|
fhahn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
Use
CRASHREPORTER_ANNOTATIONS_INITIALIZERwhen possible, which will handle the field initialization for us. That's what we already do in compiler-rt:llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
Lines 799 to 817 in 0c480dd
This way we won't get these warnings when the layout of crashreporter_annotations_t changes: